package com.atguigu.principle.command;

public class RemoteController {
    Command[] onComs;
    Command[] offComs;
    Command Com;
    public RemoteController(){
        onComs=new Command[5];
        offComs=new Command[5];
        for (int i = 0; i < 5; i++) {
            onComs[i]=new NoCommand();
            offComs[i]=new NoCommand();
        }
    }

    public void setCom(int no,Command onCom,Command offCom){
        onComs[no]=onCom;
        offComs[no]=offCom;
    }



    public void onButton(int no){
        onComs[no].execute();
        Com=onComs[no];
    }

    public void offButton(int no){
        offComs[no].execute();
        Com=offComs[no];
    }
    public void undo(){
        Com.undo();
    }
}
